/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modelo.personas.pacientes;

import java.util.HashSet;
import java.util.Set;
import javax.persistence.*;
import modelo.personas.PersonaFisica;

/**
 *
 * @author raul
 */

@Entity
public class Paciente extends PersonaFisica implements Cloneable, Comparable<Paciente> {
    
    @OneToOne (targetEntity=HistoriaClinica.class,cascade=CascadeType.ALL,fetch=FetchType.LAZY)
    private HistoriaClinica historiaClinica = new HistoriaClinica();
    
    @ManyToMany (targetEntity=Pariente.class,cascade=CascadeType.ALL,fetch=FetchType.LAZY)
    private Set<Pariente> parientes = new HashSet();

    public Paciente() {
    }

    public HistoriaClinica getHistoriaClinica() {
        return historiaClinica;
    }

    public void setHistoriaClinica(HistoriaClinica historiaClinica) {
        this.historiaClinica = historiaClinica;
    }

    public Set<Pariente> getParientes() {
        return parientes;
    }

    public void setParientes(Set<Pariente> parientes) {
        this.parientes = parientes;
    }

    @Override
    public boolean equals(Object obj) {
        return super.equals(obj);
    }

    @Override
    public int hashCode() {
        return super.hashCode();
    }
        
    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    @Override
    public int compareTo(Paciente o) {
        int result;
        if (this.equals(o)){
            result = 0;
        } else {
            result = getApellido().compareTo(o.getApellido());
            if (result == 0)
                result = getNombre().compareTo(o.getNombre());
            if (result == 0)
                result = getDocumento().compareTo(o.getDocumento());
        }
        return result;
    }
          
    
}
